<?php
class mcz_Controller
{
	protected $layout = false;
	protected $layout_vars = array();
	public function execute($action, $params = null)
	{
		$action.= 'Action';
		// it's a private method of the class or action is not a method of the class
		if (!method_exists($this, $action))
		{
			throw new Exception("Action '{$action}' is not valid!");
		}
		call_user_func_array(array(
			$this,
			$action
		) , $params);
	}
	public function setLayout($layout)
	{
		$this->layout = $layout;
	}
	public function assignToLayout($var, $value)
	{
		if (is_array($var))
		{
			array_merge($this->layout_vars, $var);
		}
		else
		{
			$this->layout_vars[$var] = $value;
		}
	}
	public function render($view, $vars = array())
	{
		if ($this->layout)
		{
			$this->layout_vars['content_for_layout'] = new mcz_View($view, $vars);
			return new mcz_View('layouts/' . $this->layout, $this->layout_vars);
		}
		else
		{
			return new mcz_View($view, $vars);
		}
	}
	public function display($view, $vars = array() , $die = true)
	{
		echo $this->render($view, $vars);
		if($die)
		{
			die;
		};
	}
}